package com.yuanfeng.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanfeng.commoms.exception.BizCodeEnume;
import com.yuanfeng.commoms.util.ResponseResult;
import com.yuanfeng.order.entity.OrderCancelReasonEntity;
import com.yuanfeng.order.mapper.OrderCancelReasonMapper;
import com.yuanfeng.order.service.OrderCancelReasonService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 *
 */
@Service
public class OrderCancelReasonServiceImpl extends ServiceImpl<OrderCancelReasonMapper, OrderCancelReasonEntity>
    implements OrderCancelReasonService{

    @Override
    public ResponseResult list(Map<String, String> paraMap) {
        List<OrderCancelReasonEntity> entities = this.baseMapper.selectList(new LambdaQueryWrapper<OrderCancelReasonEntity>()

                .eq(!paraMap.isEmpty(), OrderCancelReasonEntity::getCancelIdentity, paraMap.get("orderReturnReasonType").toString()));
        return ResponseResult.success(entities);
    }

    @Override
    public ResponseResult delete(Map<String, String> paraMap) {
        int cancelReasonId = this.baseMapper.deleteById(paraMap.get("cancelReasonId"));
        if (cancelReasonId > 0){
            return ResponseResult.success(BizCodeEnume.DELETE_SUCCESS);
        }
        return ResponseResult.fail(BizCodeEnume.DELETE_ERROR);
    }

    @Override
    public ResponseResult addCancelreason(Map<String, String> paraMap) {
        Integer integer = this.baseMapper.addCancelreason(paraMap);
        if (integer > 0){
            return ResponseResult.success(BizCodeEnume.ADD_SUCCESS);
        }
        return ResponseResult.fail(BizCodeEnume.ADD_ERROR);
    }

    @Override
    public ResponseResult updateCancelreason(Map<String, String> paraMap) {
        Integer integer = this.baseMapper.updateCancelreason(paraMap);
        if (integer > 0){
            return ResponseResult.success(BizCodeEnume.UPDATE_SUCCEEDED);
        }
        return ResponseResult.fail(BizCodeEnume.UPDATE_ERROR);
    }

}




